<template>
  <div class="packages">
    <div ref="refsTable">
      <el-form style="margin-top: 10px" label-width="68px" :inline="true">


        <el-form-item label="登记时间">
          <el-date-picker v-model="value1" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange1" style="width:380px"
            :default-time="['00:00:00', '23:59:59']" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>



        <el-form-item label="建库时间">
          <el-date-picker v-model="value2" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss" @change="timeChange2" style="width:380px"
            :default-time="['00:00:00', '23:59:59']" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>



        <el-form-item label="项目类型">
          <el-autocomplete class="inline-input" v-model="params.projectTypeName" :fetch-suggestions="querySearch"
            placeholder="请选择" @select="handleSelectProject" @focus="change(1)" style="width:228px"
            clearable></el-autocomplete>
          <!-- <el-select v-model="params.projectType" placeholder="请选择" style="width:228px">
          <el-option value="" label="全部"></el-option>
          <el-option
            v-for="item in Arr.projectTypeArr"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select> -->
        </el-form-item>



        <el-form-item label="样本类型">
          <el-autocomplete class="inline-input" v-model="params.sampleTypeName" :fetch-suggestions="querySearch"
            placeholder="请选择" @select="handleSelectSample" @focus="change(0)" style="width:228px"
            clearable></el-autocomplete>
          <!-- <el-select v-model="params.sampleType" placeholder="请选择" style="width:228px">
          <el-option value="" label="全部"></el-option>
          <el-option
            v-for="item in Arr.sampleTypeArr"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select> -->
        </el-form-item>



        <el-form-item label="核酸类型">
          <el-select v-model="params.nucleicAcidType" placeholder="请选择" style="width:228px">
            <el-option value="" label="全部"></el-option>
            <el-option v-for="item in Arr.nucleicAcidTypeArr" :key="item.id" :label="item.typeName"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>



        <el-form-item label="平台类型">
          <el-select v-model="params.platformType" placeholder="请选择" style="width:228px">
            <el-option value="" label="全部"></el-option>
            <el-option v-for="item in Arr.platformTypeArr" :key="item.id" :label="item.platformType"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>



        <el-form-item label="条码号">
          <!-- <el-autocomplete
          class="inline-input"
          v-model="params.barcodeCode"
          :fetch-suggestions="querySearch"
          placeholder="请输入条码号"
          @select="handleSelect"
          @focus="change(0)" style="width:228px"
        ></el-autocomplete> -->
          <el-input clearable v-model="params.barcodeCode" style="width:228px" placeholder="请输入条码号"></el-input>
        </el-form-item>



        <el-form-item label="实验编号">
          <!-- <el-autocomplete
          class="inline-input"
          v-model="params.experimentNumber"
          :fetch-suggestions="querySearch"
          placeholder="实验编号或流水号"
          @select="handleSelect"
          @focus="change(0)" style="width:228px"
        ></el-autocomplete> -->
          <el-input clearable v-model="params.experimentNumber" style="width:228px" placeholder="实验编号或流水号"></el-input>
        </el-form-item>



        <el-form-item label="建库状态">
          <el-select v-model="params.buildState" placeholder="请选择" style="width:228px">
            <el-option value="" label="全部"></el-option>
            <el-option v-for="item in arr.buildStateArr" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>



        <el-form-item label="质控状态">
          <el-select v-model="params.qualityControlStatus" placeholder="请选择" style="width:228px">
            <el-option value="" label="全部"></el-option>
            <el-option v-for="item in arr.qualityControlStatusArr" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>



        <el-form-item label="关键字">
          <!-- <el-autocomplete
          class="inline-input"
          v-model="params.keyword"
          :fetch-suggestions="querySearch"
          placeholder="请输入关键字"
          @select="handleSelect"
          @focus="change(1)" style="width:228px"
        ></el-autocomplete> -->
          <el-input clearable v-model="params.keyword" style="width:228px" placeholder="送检单位/姓名/建库批次号"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button size="mini" icon="el-icon-search" type="primary" @click="getList">查询</el-button>
          <el-button size="mini" icon="el-icon-refresh" @click="reset">重置</el-button>
        </el-form-item>




      </el-form>
      <el-form :inline="true">
        <el-form-item>
          <el-button size="mini" class="button-lan" type="primary" @click="buildHouse">建库</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px">
          <el-button size="mini" class="button-lan" type="primary" @click="cancelBuildHouse">取消建库</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px;float:right">
          <el-dropdown trigger="click" placement="bottom" @command="handleCommand">
            <el-button size="mini" type="primary">
              导出
              <i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="20">导出当前</el-dropdown-item>
              <el-dropdown-item command="99999">导出全部</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-form-item>
        <el-form-item style="margin-left: 10px;float:right">
          <el-button size="mini" class="button-lan" type="primary" @click="handleImport">导入</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px;float:right">
          <el-button size="mini" class="button-lan" type="primary" @click="buildHouseReturn">回退</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px;float:right">
          <el-button size="mini" type="danger" @click="batchDel">批量删除</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width:100%"
      @selection-change="handleSelectionChange" border :header-cell-style="{
        background: '#ebebeb'
      }" highlight-current-row :row-class-name="rowStyle" :height="heights" v-loading="loading">

      <el-table-column align="center" type="selection" width="55"></el-table-column>
      <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
      <el-table-column align="center" label="条码号" prop="barcodeCode" width="120"></el-table-column>
      <el-table-column align="center" prop="projectTypeName" label="项目类型" width="380"></el-table-column>
      <el-table-column align="center" prop="experimentNumber" label="实验编号" width="200"></el-table-column>
      <el-table-column align="center" prop="sampleState" label="样本状态" width="100">
        <template slot-scope="{row}">{{ row.sampleState == 1 ? '已建库' : '已提取' }}</template>
        <!-- <template slot-scope="{row}">{{arr.mainStateObj[row.mainState]}}</template> -->
      </el-table-column>
      <el-table-column align="center" prop="buildState" label="状态">
        <template slot-scope="{row}">{{ row.buildState == 1 ? '已建库' : '待建库' }}</template>
      </el-table-column>
      <el-table-column align="center" prop="buildSampleNumber" label="建库样本编号" width="200"></el-table-column>
      <el-table-column align="center" prop="buildBatchNumber" label="建库批次号" width="150"></el-table-column>
      <el-table-column align="center" prop="buildNumber" label="建库序号"></el-table-column>
      <el-table-column align="center" prop="registrationTime" label="登记时间" show-overflow-tooltip
        width='160'></el-table-column>
      <el-table-column align="center" prop="otherSampleTypes" label="其他样本类型" width="150"></el-table-column>
      <el-table-column align="center" prop="buildPerson" label="建库人"></el-table-column>
      <el-table-column align="center" prop="buildDate" label="建库日期" show-overflow-tooltip width='160'></el-table-column>
      <el-table-column align="center" prop="isBuildAgain" label="是否重建库" width="100">
        <template slot-scope="{row}">{{ row.isBuildAgain == 1 ? '是' : '否' }}</template>
      </el-table-column>
      <el-table-column align="center" prop="submitName" label="送检姓名"></el-table-column>
      <el-table-column align="center" prop="inspectionUnit" label="送检单位" width="200"
        show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="professionalGroupName" label="专业组" show-overflow-tooltip
        width='250'></el-table-column>
      <el-table-column align="center" prop="platformTypeName" label="平台类型"></el-table-column>
      <el-table-column align="center" prop="nucleicAcidName" label="核酸类型" width="100"></el-table-column>
      <el-table-column align="center" prop="sampleTypeName" label="样本类型" width="150" show-overflow-tooltip> </el-table-column>
      <el-table-column align="center" prop="kitNumber" label="试剂盒编号" width="100"></el-table-column>
      <el-table-column v-for="(item) in listTitle" :key="item.id" :label="item.label" align="center" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.technicalManagement && scope.row.technicalManagement[item.label] }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" prop label="建库投入量(ng)"></el-table-column>
      <el-table-column align="center" prop label="index"></el-table-column>
      <el-table-column align="center" prop="CRP(mg/L)" label="PCR cycles"></el-table-column>
      <el-table-column align="center" prop="buildDate" label="文库浓度(ng ul)"></el-table-column>
      <el-table-column align="center" prop label="文库体积(ul)"></el-table-column>
      <el-table-column align="center" prop label="文库总量(ng)"></el-table-column>
      <el-table-column align="center" prop label="文库大小"></el-table-column> -->
      <el-table-column align="center" prop="" label="质控内容" width="200" show-overflow-tooltip>
        <template slot-scope="{row}">
          {{ row.technicalManagement && row.technicalManagement['质控内容'] }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="qualityControlStatus" label="质控是否合格" width="100">
        <template slot-scope="{row}">{{ row.qualityControlStatus == 1 ? '是' : '否' }}</template>
      </el-table-column>
      <el-table-column align="center" prop="isVoid" label="是否作废">
        <template slot-scope="{row}">{{ row.isVoid == 1 ? '是' : '否' }}</template>
      </el-table-column>
      <el-table-column align="center" prop="reasonName" label="作废原因" width="100"
        show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="remark" label="备注" width="100" show-overflow-tooltip></el-table-column>

      <el-table-column align="center" label="操作" width="200" fixed="right">
        <template slot-scope="scope">
          <div style="">
            <el-button type="text" style="color:#0186ef;cursor:pointer;padding:0"
              @click="returnBuildHouse(scope.row)">重建库</el-button>
            <el-button type="text" style="color:#0186ef;cursor:pointer;padding:0"
              @click="edit(scope.row)">编辑</el-button>
            <el-button type="text" v-show="scope.row.isVoid == 0" style="color:#0186ef;cursor:pointer;padding:0"
              @click="nullify(scope.row.id, scope.row.stateId, scope.row)">作废</el-button>
            <el-button type="text" v-show="scope.row.isVoid == 1" style="color:#0186ef;cursor:pointer;padding:0"
              @click="toEnabled(scope.row.id, scope.row)">启用</el-button>
            <el-button v-show="scope.row.isBuildAgain === 1" type="text" style="color:red;cursor:pointer;padding:0"
              @click="del(scope.row.id)">删除</el-button>
            <el-button v-show="scope.row.isBuildAgain === 0" style="color: #999999;padding:0" type="text" disabled>删除
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>


    <el-dialog :visible.sync="importDialog" style title="excel导入" width="1200px">
      <div class="importButton">
        <!-- daoru -->
        <div style="display:flex">
          <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
            :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
            :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="true">
            <el-button size="mini" type="primary">选择Excel</el-button>
          </el-upload>
          <el-button size="mini" type="primary" @click="submitFileForm" style="margin-left:30px">提交</el-button>
        </div>
        <!-- muban -->
        <div>
          <span style="color:red;margin-right:10px">温馨提示:每次导入总数限制在500条以内</span>
          <el-button size="mini" type="primary" @click="importTemplate">模板下载</el-button>
        </div>
      </div>
      <el-table ref="multipleTable" :data="importData" tooltip-effect="dark" style="width: 100%"
        @selection-change="handleSelectionChange" border :header-cell-style="{
          background: '#ebebeb'
        }" highlight-current-row :row-class-name="rowStyle" v-loading="loading">
        <el-table-column align="center" type="selection" width="55"></el-table-column>
        <el-table-column align="center" type="index" width="50" label="序号"></el-table-column>
        <el-table-column align="center" prop="exceptionMsg" label="异常信息" show-overflow-tooltip
          width="150"></el-table-column>
        <el-table-column align="center" prop="barcodeCode" label="条码号" width="150"></el-table-column>
        <el-table-column align="center" prop="sampleNumber" label="建库样本编号" width="200"></el-table-column>
        <el-table-column align="center" prop="number" label="建库序号"></el-table-column>
        <el-table-column align="center" prop="kitNumber" label="试剂盒编号" width="100"></el-table-column>
        <!-- <el-table-column label="建库投入率(ng)">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['推力']}}</template>
        </el-table-column>
        <el-table-column label="index">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['法力']}}</template>
        </el-table-column>
        <el-table-column label="PCR cycles">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['海大力']}}</template>
        </el-table-column>
        <el-table-column label="文库浓度(ng/ul)">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['王莉莉']}}</template>
        </el-table-column>
        <el-table-column label="文库体积(ul)">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['财力']}}</template>
        </el-table-column>
        <el-table-column label="文库总量(ng)">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['财力']}}</template>
        </el-table-column>
        <el-table-column label="文库大小">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['财力']}}</template> -->
        <!-- </el-table-column> -->
        <!-- <el-table-column label="A260/A230">
          <template slot-scope="{row}">{{row.technicalManagement&&row.technicalManagement['推力']}}</template>
        </el-table-column>-->
        <el-table-column v-for="(item) in listTitle" :key="item.id" :label="item.label" align="center" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.technicalManagement && scope.row.technicalManagement[item.label] }}</span>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="importDialog = false">关闭</el-button>
      </span>

    </el-dialog>

    <el-dialog :visible.sync="nullifyDialog" style="margin-top:15vh;" title="提示" width="500px">
      <el-form :model="ruleForm2" :rules="rules2" class="demo-ruleForm" ref="ruleForm2" :inline="true">
        <el-form-item label="请输入作废原因" prop="dictReasonId">
          <el-select v-model="ruleForm2.dictReasonId" placeholder="请选择" style="width:320px">
            <el-option v-for="item in Arr.reasonNameArr" :key="item.id" :label="item.reasonName"
              :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="nullifyDialog = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="sureToNullify('ruleForm2')">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 编辑/重xx -->
    <el-dialog :visible.sync="dialogVisible" width="750px" :title="dialogTitle" @close="getList()">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="110px" class="demo-ruleForm" :inline="true"
        size="mini">
        <el-form-item label="条码号">
          <el-input clearable style="width:210px" v-model="ruleForm.barcodeCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-input clearable style="width:210px" v-model="ruleForm.projectTypeName" disabled></el-input>
        </el-form-item>
        <el-form-item label="实验编号">
          <el-input clearable style="width:210px" v-model="ruleForm.experimentNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-input clearable style="width:210px" v-model="arr.buildHouseStateObj[ruleForm.buildState]"
            disabled></el-input>
        </el-form-item>
        <el-form-item label="建库样本编号">
          <el-input clearable style="width:210px" v-model="ruleForm.buildSampleNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="建库批次号">
          <el-input clearable style="width:210px" v-model="ruleForm.buildBatchNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="录入时间">
          <el-input clearable style="width:210px" v-model="ruleForm.recordTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="建库日期">
          <el-input clearable style="width:210px" v-model="ruleForm.buildDate" disabled></el-input>
        </el-form-item>
        <el-form-item label="核酸类型">
          <el-input clearable style="width:210px" v-model="ruleForm.nucleicAcidName" disabled></el-input>
        </el-form-item>
        <el-form-item label="样本类型">
          <el-input clearable style="width:210px" v-model="ruleForm.sampleTypeName" disabled></el-input>
        </el-form-item>
        <el-form-item label="送检姓名">
          <el-input clearable style="width:210px" v-model="ruleForm.submitName" disabled></el-input>
        </el-form-item>
        <el-form-item label="送检单位">
          <el-input clearable style="width:210px" v-model="ruleForm.inspectionUnit" disabled></el-input>
        </el-form-item>
        <el-form-item v-for="(el, index) in ruleForm.listTitle" :label="el.label" :key="index">
          <el-input clearable style="width:210px"
            v-model="ruleForm.technicalManagement && ruleForm.technicalManagement[el.label]"></el-input>
        </el-form-item>


        <el-form-item label="质控是否合格" prop="qualityControlStatus" style="margin-bottom:15px">
          <el-select v-model="ruleForm.qualityControlStatus" placeholder="请选择" style="width:210px">
            <el-option v-for="item in arr.qualityControlStatusArr" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="作废原因">
          <el-input type="textarea" clearable v-model="ruleForm.reasonName" disabled style="width:540px"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" clearable v-model="ruleForm.remark" placeholder="请输入备注"
            style="width:540px"></el-input>
        </el-form-item>
        <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :default-openeds="['1']">
          <el-submenu index="1">
            <template slot="title">
              <span>临床信息</span>
            </template>
            <el-form-item label="白细胞(10⁹/L)">
              <el-input clearable style="width:210px" v-model="ruleForm.whiteBloodCells"></el-input>
            </el-form-item>
            <el-form-item label="中性粒(%)">
              <el-input clearable style="width:210px" v-model="ruleForm.neutralGrain"></el-input>
            </el-form-item>
            <el-form-item label="淋巴细胞(%)">
              <el-input clearable style="width:210px" v-model="ruleForm.lymphocyte"></el-input>
            </el-form-item>
            <el-form-item label="CRP(mg/L)">
              <el-input clearable style="width:210px" v-model="ruleForm.crp"></el-input>
            </el-form-item>
            <el-form-item label="PCT(mg/L)">
              <el-input clearable style="width:210px" v-model="ruleForm.pct"></el-input>
            </el-form-item>
            <el-form-item label="前端备注">
              <el-input clearable style="width:210px" v-model="ruleForm.frontendNote"></el-input>
            </el-form-item>
            <el-form-item label="提取浓度">
              <el-input clearable style="width:210px" v-model="ruleForm.extractionConcentration"></el-input>
            </el-form-item>
            <el-form-item label="宿主率">
              <el-input clearable style="width:210px" v-model="ruleForm.rateOfHost"></el-input>
            </el-form-item>
            <el-form-item label="主诉">
              <el-input clearable style="width:210px" v-model="ruleForm.principalComplaint"></el-input>
            </el-form-item>
            <el-form-item label="临床诊断">
              <el-input clearable style="width:210px" v-model="ruleForm.clinicalDiagnosis"></el-input>
            </el-form-item>
            <el-form-item label="用药">
              <el-input clearable style="width:210px" v-model="ruleForm.medication"></el-input>
            </el-form-item>
            <el-form-item label="重点关注病原">
              <el-input clearable style="width:210px" v-model="ruleForm.focusOnPathogen"></el-input>
            </el-form-item>
            <el-form-item label="培养鉴定结果">
              <el-input clearable style="width:210px" v-model="ruleForm.cultureIdentificationResults"></el-input>
            </el-form-item>
            <el-form-item label="发病时长">
              <el-input clearable style="width:210px" v-model="ruleForm.onsetTime"></el-input>
            </el-form-item>

            <el-form-item label="DNA结果">
              <el-input clearable style="width:210px" v-model="ruleForm.resultDna"></el-input>
            </el-form-item>
            <el-form-item label="DNA检出病原">
              <el-input clearable style="width:210px" v-model="ruleForm.resultDnaOn"></el-input>
            </el-form-item>
            <el-form-item label="RNA结果">
              <el-input clearable style="width:210px" v-model="ruleForm.resultRna"></el-input>
            </el-form-item>
            <el-form-item label="RNA检出病原">
              <el-input clearable style="width:210px" v-model="ruleForm.resultRnaOn"></el-input>
            </el-form-item>
          </el-submenu>
        </el-menu>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="resetRegister('ruleForm')">取消</el-button>
        <el-button size="mini" type="primary" @click="submitRegister('ruleForm')">确定</el-button>
      </span>
    </el-dialog>
    <!-- 回退 -->
    <el-dialog :visible.sync="returnDialog" width="750px" title="回退申请" class="returnForm">
      <el-form :model="returnData" :rules="rules3" ref="ruleForm" label-width="110px" class="demo-ruleForm"
        :inline="true">
        <el-form-item label="条码号">
          <el-input clearable style="width:210px" v-model="returnData.barcodeCode" disabled></el-input>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-input clearable style="width:210px" v-model="returnData.projectTypeName" disabled></el-input>
        </el-form-item>
        <el-form-item label="实验编号">
          <el-input clearable style="width:210px" v-model="returnData.experimentNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="样本状态">
          <!-- <el-input clearable style="width:210px" v-model="arr.buildHouseStateObj[returnData.buildState]" disabled></el-input> -->
          <el-input clearable style="width:210px" v-model="arr.mainStateObj[returnData.mainState]" disabled></el-input>
        </el-form-item>
        <el-form-item label="建库样本编号">
          <el-input clearable style="width:210px" v-model="returnData.buildSampleNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="建库批次号">
          <el-input clearable style="width:210px" v-model="returnData.buildBatchNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="核酸类型">
          <el-input clearable style="width:210px" v-model="returnData.nucleicAcidName" disabled></el-input>
        </el-form-item>
        <el-form-item label="样本类型">
          <el-input clearable style="width:210px" v-model="returnData.sampleTypeName" disabled></el-input>
        </el-form-item>
        <el-form-item label="送检姓名">
          <el-input clearable style="width:210px" v-model="returnData.submitName" disabled></el-input>
        </el-form-item>
        <el-form-item label="送检单位">
          <el-input clearable style="width:210px" v-model="returnData.inspectionUnit" disabled></el-input>
        </el-form-item>

        <el-form-item label="回退环节" prop="flowBackState">
          <el-radio-group v-model="returnData.flowBackState">
            <el-radio :label="2">入库</el-radio>
            <el-radio :label="3">提取</el-radio>
            <el-radio :label="4" disabled>建库</el-radio>
            <el-radio :label="5" disabled>测序</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="回退原因" prop="fallbackReason">
          <!-- <el-select v-model="returnData.fallbackReason" placeholder="请选择" style="width:210px">
          <el-option v-for="item in backReasonList" :key="item.id" :label="item.backReason" :value="item.backReason">
          </el-option></el-select> -->
          <el-input clearable v-model="returnData.fallbackReason" placeholder="请输入回退原因" style="width:210px"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="resetRegister2('ruleForm')">取消</el-button>
        <el-button size="mini" type="primary" @click="submitRegister2('ruleForm')">确定</el-button>
      </span>
    </el-dialog>
    <div class="block">
      <div>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :page-sizes="[20, 50, 100, 200, 500]" layout="total, sizes, prev, pager, next, jumper" :total="listTotal"
          background></el-pagination>
      </div>
    </div>
  </div>
</template>
    
<script>
import {
  exportBuildHouse,
  buildHouseList,
  delBuildHouse,
  buildHouseToVoid,
  sureToBuildHouse,
  reBuildHouse,
  submitBuildHouseExcel,
  exportBuildHouseTemplate,
  cancelBuildHouse,
  buildHouseEdit,
  returnApply,
  buildEnabled,
  getDictTechnicalFields,

} from "@/api/technologyManage/index.js";
import { manageBackList, manageBackAdd } from '@/api/comprehensiveSearchManage/fallback.js'

import { voidPlaceOn, delPlaceOn, manageOperation } from '@/api/commonArr/index.js'
import { arr, Arr } from "@/utils/data.js";
import { getToken } from "@/utils/auth";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      projectTypeList: [],
      sampleTypeList: [],
      loading: false,
      value1: [],
      value2: [],
      multipleSelection: [],
      restaurants: [],
      tableData: [],
      stateId: '',
      dialogVisible: false,
      row: {},
      rules: {
        qualityControlStatus: [{ required: true, message: "请输入质控状态", trigger: "blur" }]
      },
      rules2: {
        dictReasonId: [
          { required: true, message: "请输入作废原因", trigger: "change" }
        ]
      },
      ruleForm2: {},
      ruleForm: {
        technicalManagement: {},
        listTitle: [
        ]
      },
      nullifyDialog: false,
      dialogTitle: "",
      importDialog: false,
      uploadHeader: {
        Authorization: ""
      },
      params: {
        pageNum: 1,
        pageSize: 20,
        projectType: '',
        sampleType: '',
        nucleicAcidType: '',
        platformType: '',
        experimentalStatus: '',
        buildState: '',
        qualityControlStatus: ''
      },
      listTotal: 0,
      arr: {},
      Arr: {},
      id: "",
      upload: {
        // 是否显示弹出层(用户导入)
        open: false,
        // 弹出层标题(用户导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/process/build/importDataList"
      },
      importData: [],
      ids: [],
      returnDialog: false,
      returnData: {},
      rules3: {
        fallbackReason: [{ required: true, message: '请输入回退原因', trigger: 'blur' }],
        flowBackState: [{ required: true, message: '请选择回退环节', trigger: 'change' }],
      },
      listTitle: [
      ],
      heights: undefined,
      backReasonList: []
    };
  },
  created() {
    this.watchTableHights()
    this.uploadHeader.Authorization = `Bearer ${getToken()}`;
  },
  methods: {
    // 下拉框
    querySearch(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    // 多个下拉框的数据
    loadAll() {
      const array = [
        this.sampleTypeList,
        this.projectTypeList,

      ];
      return array;
    },
    handleSelect(item) {
      console.log(item);
    },
    // 聚焦下拉框时
    change(i) {
      this.restaurants = this.loadAll()[i];
      // console.log(this.restaurants);
    },
    // 表格复选框
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = val.map(item => item.id);
    },
    // 编辑界面
    edit(row) {
      this.ruleForm = row;
      this.ruleForm.listTitle = this.listTitle
      this.dialogTitle = "建库：编辑";
      this.dialogVisible = true;
    },
    batchDel() {
      if (
        this.multipleSelection.length === 0
      ) {
        this.$message.error("请勾选内容");
        return;
      }
      this.$confirm("是否批量删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let idList = []
        this.multipleSelection.map(el => {
          idList.push(el.id)
        })
        delBuildHouse(idList).then(() => {
          this.getList()
          this.$message.success('批量删除成功')
        })
      })
    },
    returnBuildHouse(row) {
      this.row = row
      this.ruleForm = row;
      this.ruleForm.listTitle = this.listTitle
      let obj = {}
      for (let k in this.ruleForm.technicalManagement) {
        obj[k] = ""
      }
      this.ruleForm.technicalManagement = obj
      this.dialogTitle = "建库：重建库";
      this.dialogVisible = true;
    },
    // 作废
    nullify(id, stateId, row) {
      this.stateId = stateId
      this.id = id;
      this.row = row
      this.nullifyDialog = true;
    },
    voidPlaceOn() {
      voidPlaceOn({ stateId: this.stateId, status: 0 }).then(() => {
      })
    },
    // 确认作废
    sureToNullify(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          buildHouseToVoid({
            dictReasonId: this.ruleForm2.dictReasonId,
            id: this.id
          }).then(() => {
            this.$message.success("已作废");
            this.nullifyDialog = false;
            this.getList();
            this.voidPlaceOn()
            this.row.status = 0
            this.row.operationStatus = 0
            manageOperation(this.row)
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    //编辑
    submitRegister(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if (this.dialogTitle === "建库：编辑") {
            buildHouseEdit(this.ruleForm).then(() => {
              buildHouseEdit(this.ruleForm).then(() => {
                this.$message.success("修改成功");
                this.dialogVisible = false;
                this.ruleForm = {};
                this.getList()
              })

            });
          } else if (this.dialogTitle === "建库：重建库") {
            reBuildHouse(this.ruleForm).then(() => {
              this.$message.success("重建库成功");
              this.dialogVisible = false;
              this.ruleForm = {};
              this.getList()
              this.row.status = 0
              this.row.operationStatus = 2
              manageOperation(this.row)
            });

          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    submitRegister2(formName) {
      const data = {
        fallbackReason: this.returnData.fallbackReason,
        flowBackState: this.returnData.flowBackState,
        stateId: this.returnData.stateId
      };
      this.$refs[formName].validate(valid => {
        if (valid) {
          returnApply(data).then(() => {
            this.$message.success("回退成功");
            this.returnDialog = false;
            this.getList()
            this.multipleSelection[0].backReason = this.returnData.fallbackReason
            // this.multipleSelection[0].status=this.returnData.flowBackState
            this.multipleSelection[0].status = 20
            this.multipleSelection[0].projectTypeId = this.multipleSelection[0].projectType
            this.multipleSelection[0].nucleicAcidTypeId = this.multipleSelection[0].nucleicAcidType
            this.multipleSelection[0].platformTypeId = this.multipleSelection[0].platformType
            this.multipleSelection[0].sampleTypeId = this.multipleSelection[0].sampleType
            this.multipleSelection[0].nucleicAcidTypeName = this.multipleSelection[0].nucleicAcidName
            manageBackAdd(this.multipleSelection[0])
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    del(id) {
      this.$confirm("是否删除选中数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return delBuildHouse(id);
        })
        .then(() => {
          this.getList();
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        });
    },
    resetRegister(formName) {
      this.$refs[formName].resetFields(); //清空
      this.dialogVisible = false;
      this.getList()
    },
    resetRegister2(formName) {
      this.$refs[formName].resetFields(); //清空
      this.returnDialog = false;
    },

    buildHouse() {
      if (this.multipleSelection.length == 0) {
        this.$message.error("请勾选内容");
        return;
      }

      this.ids = []
      this.$confirm("是否建库?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.multipleSelection.forEach(el => {
          this.ids.push(el.id);
        });
        return sureToBuildHouse({ ids: this.ids });
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "建库成功!"
          });
          this.getList()
        });
    },
    cancelBuildHouse() {
      if (
        this.multipleSelection.length === 0
      ) {
        this.$message.error("请勾选内容");
        return;
      }
      this.$confirm("是否取消建库?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let ids = []
          this.multipleSelection.forEach(el => {
            ids.push(el.id);
          });
          return cancelBuildHouse(ids);
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "取消建库成功!"
          });
          this.getList()
        });
    },
    handleImport() {
      this.importDialog = true;
    },

    handleExport() {
      const queryParams = this.params;
      this.$confirm("是否确认导出数据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function () {
          return exportBuildHouse(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.params.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.pageNum = val;
      this.getList();
    },
    getList() {
      this.loading = true
      buildHouseList(this.params).then(res => {
        this.tableData = res.rows;
        this.listTotal = res.total;
        this.loading = false
      });
    },
    timeChange1() {
      if (!this.value1) {
        this.value1 = []
      }
      this.params.registrationStartTime = this.value1[0];
      this.params.registrationEndTime = this.value1[1];
    },
    timeChange2() {
      if (!this.value2) {
        this.value2 = []
      }
      this.params.buildStartDate = this.value2[0];
      this.params.buildEndDate = this.value2[1];

    },
    importTemplate() {
      exportBuildHouseTemplate().then(res => {
        this.download(res.msg);
      });
    },
    reset() {
      this.params = {
        pageSize: 20,
        pageNum: 1,
        projectType: '',
        sampleType: '',
        nucleicAcidType: '',
        platformType: '',
        experimentalStatus: '',
        buildState: '',
        qualityControlStatus: ''
      };
      this.value1 = []
      this.value2 = []
      this.getList();
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      console.log(response);
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.importData = response.data.importData;
    },
    submitFileForm() {
      this.$confirm("是否提交选中数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        submitBuildHouseExcel({ importData: this.multipleSelection }).then(() => {
          this.$message.success("提交成功");
          this.multipleSelection = [];
          this.importDialog = false
          this.getList()
          this.importData = []
        });
      });
    },
    buildHouseReturn() {
      if (this.multipleSelection.length == 0) {
        this.$message.error('请勾选内容')
        return
      }
      if (this.multipleSelection.lenght > 1) {
        this.$message.error('至多选一项')
        return
      }
      this.returnDialog = true;
      this.returnData = this.multipleSelection[0];
      manageBackList({ pageNum: 1, pageSize: 999 }).then(res => {
        this.backReasonList = res.rows
      })
    },
    toEnabled(id, row) {
      this.$confirm("是否确认启用?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        buildEnabled({ id }).then(() => {
          this.$message.success('启用成功')
          this.getList()
          delPlaceOn(row.stateId)
        })
      })
    },
    getDictTechnicalFields() {
      // 技术环节(10=提取,20=建库,30=测序)
      getDictTechnicalFields(20).then(res => {
        res.data.forEach((el, i) => {
          this.listTitle.push({ id: i, label: el.fieldContent })
        });
      });
    },
    rowStyle({ row }) {
      var arr = this.ids;
      for (let i = 0; i < arr.length; i++) {
        if (row.id === arr[i]) {
          return "rowStyle";
        }
      }
    },
    handleCommand(command) {
      this.params.pageSize = command
      this.handleExport()
    },
    watchTableHights() {
      this.$nextTick(() => {
        // 根据浏览器高度设置初始高度
        this.heights =
          window.innerHeight - this.$refs.refsTable.offsetHeight - 150;
        // 监听浏览器高度变化，修改表格高度
        window.onresize = () => {
          this.heights =
            window.innerHeight - this.$refs.refsTable.offsetHeight - 150;
        };
      });
    },
    getDefaultDate() {
      var now = new Date();
      var date = now.getDate();
      // now.setDate(date - 1);  //获取前一天
      var y = now.getFullYear();
      var m = (now.getMonth() + 1).toString().padStart(2, "0");
      var d = now.getDate().toString().padStart(2, "0");
      var defaultDate = y + "-" + m + "-" + d + ' ' + '00:00:00';

      var defaultDate2 = y + "-" + m + "-" + d + ' ' + '23:59:59';
      this.$set(this.value1, 0, defaultDate),
        this.$set(this.value1, 1, defaultDate2)
      // this.$set(this.value2,0,defaultDate),
      // this.$set(this.value2,1,defaultDate2)
      this.timeChange1()
      // this.timeChange2()
    },
    handleSelectSample(item) {
      this.params.sampleType = item.id
    },
    handleSelectProject(item) {
      this.params.projectType = item.id
    },
  },
  created() {
    this.getDefaultDate()
    Arr.sampleTypeArr.map(el => {
      this.sampleTypeList.push({
        value: el.name,
        id: el.id
      })
    })
    Arr.projectTypeArr.map(el => {
      this.projectTypeList.push({
        value: el.name,
        id: el.id
      })
    })
  },
  mounted() {
    this.watchTableHights()
    this.getList();
    this.getDictTechnicalFields()

    this.arr = arr
    this.Arr = Arr
    // this.Arr.sampleTypeArr.map(el=>{
    //   this.sampleTypeList.push({
    //     value:el.name
    //   })
    // })
  },
  updated() {
    this.$refs['multipleTable'].doLayout()
  }
};
</script>
    
<style lang="scss" scoped>
.packages {
  padding-left: 20px;

  // position: relative;
  .czDiv {
    width: 100%;
    height: 100%;
    display: flex;
    padding: 0 15px 0 15px
  }

  .importButton {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
  }

  .block {
    width: 100%;
    // height: 50px;
    background-color: #fff;
    position: absolute;
    display: flex;
    flex-direction: row-reverse;
    bottom: 10px;
    right: 20px;
    z-index: 99;
  }

  .el-col-5 {
    width: 20%;
  }

  .el-autocomplete {
    width: 216px
  }

  ::v-deep .el-table__body tr.current-row>td {

    background: #a8d6fe !important;
  }

  ::v-deep .rowStyle {
    background-color: #a8d6fe !important;
  }

  ::v-deep .el-table__body tr:hover>td {
    background: #a8d6fe !important;
  }

  .el-row {
    display: flex;
    flex-wrap: wrap;
  }

  .el-form-item {
    margin-bottom: 10px;
  }

  .returnForm {
    .el-form-item {
      margin-bottom: 17px;
    }
  }

  .topDiv {

    ::v-deep .el-form-item__label {
      font-size: 12px;
      padding: 0 5px 0 0;
      margin: 0;

    }

  }
}
</style>